package com.sfc.spiderweb.task;

import com.alibaba.fastjson.JSONObject;
import com.sfc.spiderweb.entity.po.DynamicMessageToUsersReqParam;
import com.sfc.spiderweb.entity.po.TemplateMessageReqParam;
import com.sfc.spiderweb.entity.po.UserMessageReqParam;
import com.sfc.spiderweb.util.HttpClient;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class DingTalkSchedule {
    //3.添加定时任务
    @Scheduled(cron = "0 0 17 * * ?")
    //@Scheduled(cron = "*/5 * * * * ?")
    private void configureTasks() {
        String url = "http://47.112.12.109:8898/dingDing/employee/dynamicMessage";
        DynamicMessageToUsersReqParam param = new DynamicMessageToUsersReqParam();
        param.setMessageType("text");
        param.setTemplateId(0);
        param.setSystemId(2);
        param.setTitle("title");
        String message = "别忘记填写今天的会议记录哦";
        List<UserMessageReqParam> userMessageReqParams = new ArrayList<>();
        List<String> list = Arrays.asList("PZWG1248","XAST003","PZWG1304","PZWG1345","SFC1582","XAST023");
        for (String s : list) {
            UserMessageReqParam userMessageReqParam = new UserMessageReqParam(s,message);
            userMessageReqParams.add(userMessageReqParam);
        }
        param.setUserMessageList(userMessageReqParams);
        param.setValidToken("aUHVJoX3Z4CZExFCsJKmXwR/hBoehrG/5EJoJXjrFR1ScbrONL1sFQIu24Qr5l5TvTk1XKT5voeQsoG+7ttzgT2ph1k2NYw0tg1zXm50szz/C5S/D8HJYkSLWZkYKY252kQLeBaO9lsWpy0NxpeARfW6lBWLve3k5z1wlNRqqz4=");
        String post = HttpClient.doPost(url, JSONObject.toJSONString(param), "POST");
        System.out.println(post);
    }
}